#! /usr/bin/env python
#*
#*  Copyright (c) 2009, Willow Garage, Inc.
#*  All rights reserved.
#*
#*  Redistribution and use in source and binary forms, with or without
#*  modification, are permitted provided that the following conditions
#*  are met:
#*
#*   * Redistributions of source code must retain the above copyright
#*     notice, this list of conditions and the following disclaimer.
#*   * Redistributions in binary form must reproduce the above
#*     copyright notice, this list of conditions and the following
#*     disclaimer in the documentation and/or other materials provided
#*     with the distribution.
#*   * Neither the name of the Willow Garage nor the names of its
#*     contributors may be used to endorse or promote products derived
#*     from this software without specific prior written permission.
#*
#*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
#*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
#*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
#*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
#*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#*  POSSIBILITY OF SUCH DAMAGE.
#***********************************************************

# Author: Blaise Gassend

# WGE100 camera configuration

PACKAGE='gazebo_plugins'
#import roslib; roslib.load_manifest(PACKAGE)

#from dynamic_reconfigure.parameter_generator import *
#from gazebo_plugins.levels import * # Get the levels
from dynamic_reconfigure.parameter_generator_catkin import *

#copy from levels.py.  Leaving levels.py in gazebo_plugins/src results in compile error.
lvl_narrow = 1
lvl_wide = 2
lvl_forearm_r = 4
lvl_forearm_l = 8
lvl_projector = 16
lvl_stereo = lvl_wide | lvl_narrow
lvl_all = lvl_stereo | lvl_forearm_r | lvl_forearm_l | lvl_projector

gen = ParameterGenerator()

p_off   = gen.const("ProjectorOff", int_t, 1, "The projector is always off.")
p_auto  = gen.const("ProjectorAuto", int_t, 2, "The projector is on if one of the cameras is using it.")
p_on    = gen.const("ProjectorOn", int_t, 3, "The projector is always on.")
projector_mode_enum = gen.enum([ p_off, p_auto, p_on ], "The projectors operating mode.")

t_int    = gen.const("InternalTrigger",    int_t, 1, "The camera does not use the trigger input.")
t_ign    = gen.const("IgnoreProjector",    int_t, 2, "The cameras frequency can be set independently of the projector frequency. There is no deterministic phase relation between projector firing and camera triggering.")
t_proj   = gen.const("WithProjector",      int_t, 3, "The camera always exposes while the projector is on.")
t_noproj = gen.const("WithoutProjector",   int_t, 4, "The camera always exposes while the projector is off.")
t_alt    = gen.const("AlternateProjector", int_t, 5, "The camera alternates between frames with and without the projector.")
wide_trig_mode_enum    = gen.enum([ t_ign, t_proj, t_noproj ], "The triggering mode for the wide camera.")
narrow_trig_mode_enum  = gen.enum([ t_ign, t_proj, t_noproj, t_alt ], "The triggering mode for the narrow camera.")
forearm_trig_mode_enum = gen.enum([ t_int, t_ign, t_proj, t_noproj ], "The triggering mode for a forearm camera.")

#       Name                                 Type      Reconf level   Description                                                                                                                                    Default    Min   Max
gen.add("projector_rate",                    double_t, lvl_all,       "Projector pulse frequency in Hz.",                                                                                                            60.0,      40.0, 120.0)
gen.add("projector_pulse_length",            double_t, lvl_all,       "Length of the projector pulses in s. At high currents the hardware may limit the pulse length.",                                              0.002,     0.001,0.002)
gen.add("projector_pulse_shift",             double_t, lvl_all,       "How far off-center the intermediate projector pulses are. Zero is on-center, one is touching the following pulse.",                           0.0,       0.0,  1.0)
gen.add("projector_mode",                    int_t,    lvl_all,       "Indicates whether the projector should be off, on when in use or on all the time.",                                                           2,         1,    3,    edit_method = projector_mode_enum)
gen.add("prosilica_projector_inhibit",       bool_t,   lvl_projector, "Indicates if the projector should turn off when the prosilica camera is exposing.",                                                           False)

gen.add("stereo_rate",                       double_t, lvl_stereo,    "Indicates the frame rate for both stereo cameras in Hz. (Gets rounded to suitable divisors of projector_rate.)",                             30.0,      1.0,  60.0)

gen.add("wide_stereo_trig_mode",             int_t,    lvl_stereo,    "Indicates the triggering mode of the wide stereo camera.",                                                                                    4,         2,    4,    edit_method = wide_trig_mode_enum)
gen.add("narrow_stereo_trig_mode",           int_t,    lvl_stereo,    "Indicates the triggering mode of the narrow stereo camera.",                                                                                  4,         2,    5,    edit_method = narrow_trig_mode_enum)

gen.add("forearm_r_rate",                    double_t, lvl_forearm_r, "Indicates the frame rate for the right forearm camera in Hz. (Gets rounded to suitable divisors of projector_rate.)",                        30.0,      1.0,  60.0)
gen.add("forearm_r_trig_mode",               int_t,    lvl_forearm_r, "Indicates the triggering mode of the right forearm camera.",                                                                                  1,         1,    4,    edit_method = forearm_trig_mode_enum)

gen.add("forearm_l_rate",                    double_t, lvl_forearm_l, "Indicates the frame rate for the left forearm camera in Hz. (Gets rounded to suitable divisors of projector_rate.)",                         30.0,      1.0,  60.0)
gen.add("forearm_l_trig_mode",               int_t,    lvl_forearm_l, "Indicates the triggering mode of the left forearm camera.",                                                                                   1,         1,    4,    edit_method = forearm_trig_mode_enum)

gen.add("projector_tweak",                   double_t, lvl_all,       "Adds a time shift in seconds to the projector timing. Useful for debugging but not in normal use.",                                           0,         -0.1, 0.1)

gen.add("camera_reset",                      bool_t,   lvl_all,       "Does a hard reset of all the cameras using a long pulse on the trigger line. This parameter resets itself to false after 3 to 4 seconds.",        False)

exit(gen.generate(PACKAGE, "camera_synchronizer",     "CameraSynchronizer"))
